package com.ysz.timewheel.client.task;

import com.ysz.timewheel.server.conn.ServerConn;
import com.ysz.timewheel.server.struct.ClientStruct;
import org.apache.commons.lang3.StringUtils;

import java.util.concurrent.Callable;

/**
 * @ClassName RegisterTask
 * @Description 客户端注册任务
 * @Data 13:35
 * @Version 1.0
 * @Author ysz
 */
public class RegisterTask implements Callable<Integer> {

    private String ip;

    public RegisterTask(String ip) {
        if (StringUtils.isEmpty(ip)) {
            throw new IllegalArgumentException("ip参数不能为空");
        }
        this.ip = ip;
    }


    @Override
    public Integer call() throws Exception {
        //构建客户端数据结构
        ClientStruct clientStruct = new ClientStruct(ip, null);
        ServerConn serverConn = new ServerConn();
        //模拟客户端连接探活服务
        return serverConn.accept(clientStruct);
    }
}
